<?php
/* SVN FILE: $Id: lil_blogs_wysiwyg_plugin_controller.php 162 2009-10-14 19:48:36Z miha@nahtigal.com $ */
/**
 * Short description for lil_blogs_wysiwyg_plugin_controller.php
 *
 * Long description for lil_blogs_wysiwyg_plugin_controller.php
 *
 * PHP versions 4 and 5
 *
 * Copyright (c) 2009, Miha Nahtigal
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright (c) 2009, Miha Nahtigal
 * @link          http://www.nahtigal.com/
 * @package       lil_blogs_wysiwyg_plugin
 * @subpackage    lil_blogs_wysiwyg_plugin
 * @since         v 1.0
 * @version       $Revision: 162 $
 * @modifiedby    $LastChangedBy: miha@nahtigal.com $
 * @lastmodified  $Date: 2009-10-14 21:48:36 +0200 (sre, 14 okt 2009) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */
App::import('Controller', 'LilBlogs.LilBlogsPlugin');
/**
 * LilBlogsWysiwygPlugin class
 *
 * @uses          LilBlogsWysiwygPluginController
 * @package       lil_blogs_wysiwyg_plugin
 * @subpackage    lil_blogs_wysiwyg_plugin
 */
class LilBlogsWysiwygPluginController extends LilBlogsPluginController {
/**
 * initialize method
 *
 * This is a plugins initialization method
 *
 * @access public
 * @return void
 */
	function _initialize() {
		$this->attachHandler('form_edit_post', '_initWysiwyg');
		$this->attachHandler('form_add_post', '_initWysiwyg');
	}
/**
 * _initWysiwyg method
 *
 * This replaces textarea with CKEditor and sets properties
 *
 * @param mixed $model
 * @access public
 * @return void
 */
	function _initWysiwyg($view, $form_data) {
		if (App::import('Helper', 'Javascript')) {
			$Javascript = new JavascriptHelper();
			$form_data['form']['post'] .= 
				$Javascript->link(Router::url('/', true) . 'lil_blogs_wysiwyg/js/ckeditor/ckeditor.js', true) . PHP_EOL . 
				'<script type="text/javascript">' . PHP_EOL . 
				'	CKEDITOR.addStylesSet(\'lilblogs_styles\', [' . PHP_EOL .
				'		{ name : \'' . __d('lil_blogs_wysiwyg', 'Normal', true) . '\', element : \'div\', styles : {} },' . PHP_EOL .
				'		{ name : \'' . __d('lil_blogs_wysiwyg', 'Paragraph 1', true) . '\', element : \'h1\' },' . PHP_EOL .
				'		{ name : \'' . __d('lil_blogs_wysiwyg', 'Paragraph 2', true) . '\', element : \'h2\' },' . PHP_EOL .
				'		{ name : \'' . __d('lil_blogs_wysiwyg', 'Paragraph 3', true) . '\', element : \'h3\' },' . PHP_EOL .
				'		{ name : \'' . __d('lil_blogs_wysiwyg', 'Caption', true) . '\', element : \'div\', attributes: {\'class\': \'caption\'} },' . PHP_EOL .
				'		{ name : \'' . __d('lil_blogs_wysiwyg', 'Preformatted', true) . '\', element : \'pre\' },' . PHP_EOL .
				'	]);' . PHP_EOL .
				'	CKEDITOR.replace( \'data[Post][body]\', {' . PHP_EOL .
				'		toolbar: [[\'Styles\',\'-\',\'Bold\',\'Italic\',\'Underline\',\'Strike\',\'-\',\'NumberedList\',\'BulletedList\',\'-\',\'Link\',\'Unlink\',\'Image\',\'-\',\'Undo\',\'Redo\',\'RemoveFormat\',\'-\',\'Source\']], ' . PHP_EOL .
				'		width: 600,' . PHP_EOL .
				'		resize_maxWidth: 600,' . PHP_EOL .
				'		resize_minWidth: 600,' . PHP_EOL .
				'		baseHref : \'' . Router::url('/', true) . '\',' . PHP_EOL .
				'		customConfig : \'\',' . PHP_EOL .
				'		stylesCombo_stylesSet : \'lilblogs_styles\'' . PHP_EOL .
					
				'	});' . PHP_EOL . 
				'</script>' . PHP_EOL;
			}
		return $form_data;
	}

}
?>